package com.nf.action;

import com.nf.entity.User;
import com.nf.service.UserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@Scope("prototype")
public class UserAction extends ActionSupport {

    @Autowired
    private UserService userService;

    private Map<String,Object> myMap = new HashMap<String,Object>();
    public Map<String, Object> getMyMap() {
        return myMap;
    }
    public void setMyMap(Map<String, Object> myMap) {
        this.myMap = myMap;
    }

    public String getAllUser(){
        List<User> userList = userService.getAllUser();
        System.out.println("userList:"+userList.size());
        ActionContext.getContext().getValueStack().set("userList",userList);
        return this.SUCCESS;
    }

    public String getAllUserToJSON(){
        List<User> userList = userService.getAllUser();
        myMap.put("userList",userList);
        return this.SUCCESS;
    }

}
